package com.zyj.eps.controller;

import com.alibaba.fastjson.JSON;
import com.zyj.eps.pojo.Temperature;
import com.zyj.eps.service.TemperatureServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;

/**
 * @author super
 * @date 2022/4/1 17:56
 */
@Controller
@RestController
@CrossOrigin
@SuppressWarnings("all")//抑制警告
public class TemperatureController {
    @Autowired
    private TemperatureServiceImpl temperatureService;

    @RequestMapping("/insetTemperature")
    public String insetTemperature(@RequestBody Temperature temperature){
        System.out.println(temperature);
        int i = temperatureService.insetTemperature(temperature);
        if(i!=0){
            return JSON.toJSONString("ok");
        }else {
            return JSON.toJSONString("error");
        }
    }
    @RequestMapping("/getAllTemperature")
    public String getAllTemperature(int tid){
        List<Temperature> allTemperature = temperatureService.getAllTemperature(tid);
        Collections.reverse(allTemperature); //实现list集合逆序排列
        System.out.println(allTemperature);
        return JSON.toJSONString(allTemperature);
    }

}
